import java.util.*;
public class QueueLinkedList  {
    public class LinkedQueue {
        private class ListQ {
            public   Object data;
            public ListQ next;
            public ListQ (Object data, ListQ next) {
                this.data = data;
                this.next = next;
            }
        }

        private ListQ head = null;
        private ListQ tail = null;
        public Object element (){
            if(head==null)
            throw new NoSuchElementException();
            return head.data;
        }
        boolean offer(Object element ) throws ClassCastException, NullPointerException,IllegalArgumentException {
            ListQ listQ=new ListQ(element,null);
            if(head==null){
                head=listQ;
            }else {
          tail.next=listQ;}
          tail=listQ;
          return true;
        }
        public Object peek(){
            if(head==null){
                return null;
            }
            return head.data;
        }
       public Object poll(){
           if(head==null){
               return null;
           }
           Object first=head.data;
           head=head.next;
           return first;
           }
        public Object remove(){
            if(head!=null){
                Object first=head.data;
                head=null;
                return first;
            } else
                 throw new NoSuchElementException();
        }
    }
}




